package com.example.charlotte.snakegame;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.support.annotation.Nullable;

/**
 * Created by Charlotte on 2018/12/2.
 */

public class BGMService extends Service{
    private MediaPlayer mediaPlayer;

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }


    @Override
    public void onCreate() {
        super.onCreate();

        mediaPlayer=new MediaPlayer();
        mediaPlayer = MediaPlayer.create(this, R.raw.main);
    }

    @Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
            mediaPlayer.setLooping(true);
            mediaPlayer.start();

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mediaPlayer.stop();
        mediaPlayer.release();

    }

}
